package com.financing.platform.web.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.common.ResultMap.STATUS;
import com.financing.platform.dto.ProductNoticeDTO;
import com.financing.platform.service.IProductNoticeService;
import com.financing.platform.util.DTOdateSet;

@Controller
@RequestMapping("/api/productNotice")
@Scope("prototype")
public class FpProductNoticeAction extends BaseAction {
	
	@Autowired
	IProductNoticeService productNoticeService;
	
	/**
	 *查询产品成立公告
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/queryProductNotice.shtml")
	@ResponseBody
	public ResultMap queryProductNotice(HttpServletRequest request,
			HttpServletResponse response, ProductNoticeDTO productNoticeDTO,
			Pager pager) {
		try {
			log.info("Begin queryProductNotice list!");
			productNoticeDTO.setBegin(pager.getStartIndex());
			productNoticeDTO.setPageSize(pager.getPageSize());
			List<ProductNoticeDTO> list = productNoticeService
					.queryProdcutNoticeList(productNoticeDTO);
			
			pager.setTotalCount(productNoticeService.countProdcutNoticeList(productNoticeDTO));
			
			resultMap.setAttribute("list", list);
			resultMap.setAttribute("pager", pager);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End queryProductNotice!");
		} catch (Exception e) {
			log.error("queryProductNotice error !", e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		return resultMap;
	}
	
	/**
	 *查询产品成立公告详情
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/queryProductNoticeDetail.shtml")
	@ResponseBody
	public ResultMap queryProductNoticeDetail(HttpServletRequest request,
			HttpServletResponse response, ProductNoticeDTO productNoticeDTO) {
		try {
			log.info("Begin queryProductNoticeDetail!");
			ProductNoticeDTO queryProdcutNoticeDetail = productNoticeService.queryProdcutNoticeDetail(productNoticeDTO);
			resultMap.setAttribute("queryProdcutNoticeDetail",queryProdcutNoticeDetail);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End queryProductNoticeDetail!");
		} catch (Exception e) {
			log.error("queryProductNoticeDetail error !", e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		return resultMap;
	}
	/**
	 *编辑产品成立公告详情
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/updateProductNotice.shtml")
	@ResponseBody
	public ResultMap updateProductNotice(HttpServletRequest request,
			HttpServletResponse response, ProductNoticeDTO productNoticeDTO) {
		try {
			log.info("Begin updateProductNotice!");
			DTOdateSet.setUpdateInfo(productNoticeDTO, request.getSession());
			int updateProdcutNotice = productNoticeService.updateProdcutNotice(productNoticeDTO);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			log.info("End updateProductNotice!");
		} catch (Exception e) {
			log.error("updateProductNotice error !", e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
		return resultMap;
	}
}
